package com.authine.cloudpivot.ext.applicationservice.homepagedata;

import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.applicationservice.authority.RoleApi;
import com.authine.cloudpivot.ext.applicationservice.organization.UserApi;
import com.authine.cloudpivot.ext.constants.AppConst;
import com.authine.cloudpivot.ext.constants.ModelConst;
import com.authine.cloudpivot.ext.dto.system.OrganizationDto;
import com.authine.cloudpivot.ext.dto.system.RoleDto;
import com.authine.cloudpivot.ext.dto.system.UserDto;
import com.authine.cloudpivot.ext.enums.inquiry.VendorScopeEnum;
import com.authine.cloudpivot.ext.enums.system.ArchitectureCateEnum;
import com.authine.cloudpivot.ext.utils.JdbcTemplateUtils;
import com.authine.cloudpivot.ext.utils.system.OrgUtils;
import com.authine.cloudpivot.ext.utils.system.RoleUtils;
import com.authine.cloudpivot.ext.utils.system.UserUtils;
import com.authine.hermes.app.launcher.service.ApplicationService;
import com.authine.mvp.app.launcher.domain.SelectorFormat;
import com.authine.mvp.app.launcher.domain.utills.ApplicationContextUtils;
import com.authine.mvp.app.launcher.dto.bo.response.BOList;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
public class CountService extends ApplicationService {

    private static final NamedParameterJdbcTemplate jdbcTemplate = ApplicationContextUtils.getBean(NamedParameterJdbcTemplate.class);
    private static final String InquiryGoodsName = JdbcTemplateUtils.getTableName(ModelConst.T_INQUIRY_GOODS, AppConst.SOURCING_CENTER);
    private static final String InquiryName = JdbcTemplateUtils.getTableName(ModelConst.T_INQUIRY, AppConst.SOURCING_CENTER);
    private static final String QuotationGoodsName = JdbcTemplateUtils.getTableName(ModelConst.T_QUOTATION_GOODS, AppConst.SOURCING_CENTER);
    private final UserApi userApi = new UserApi();
    private final RoleApi roleApi = new RoleApi();

    public Map<String,Object> countMainInfo(String orgId) {

        Map<String, Object> hashMaps = new HashMap<>();

        if (orgId==null){
            log.error("组织id不能为null");
        }

        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);

        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.DATE, todayStart.get(Calendar.DATE) + 1);
        todayEnd.set(Calendar.HOUR_OF_DAY, 0);
        todayEnd.set(Calendar.MINUTE, 0);
        todayEnd.set(Calendar.SECOND, 0);
        todayEnd.set(Calendar.MILLISECOND, 0);

        //今日开始时间和结束时间
        Date todayStartTime = todayStart.getTime();
        Date todayEndTime = todayEnd.getTime();

        //类型转换
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String startFormat = simpleDateFormat.format(todayStartTime);
        String endFormat = simpleDateFormat.format(todayEndTime);


        //获取昨天开始时间和结束时间
        Date yesterdayEnd = todayStart.getTime();
        int i = todayStart.get(Calendar.DATE);
        todayStart.set(Calendar.DATE, i - 1);
        Date yesterdayStart = todayStart.getTime();

        String ydStartFormat = simpleDateFormat.format(yesterdayStart);
        String ydEndFormat = simpleDateFormat.format(yesterdayEnd);


        List<String> memberIds = new ArrayList<>();
        List<String> orgIds = new ArrayList<>();

        //根据组织id获取集团下所有组织
        List<OrganizationDto> orgListByOrgId = OrgUtils.getOrgListByOrgId(orgId);
        for (OrganizationDto organizationDto : orgListByOrgId) {
            String id = organizationDto.getId();
            orgIds.add(id);
        }

        //获取组织内的用户ID列表,包括子组织
        OrganizationDto organizationDto = new OrganizationDto();
        organizationDto.setIds(orgIds);
        List<String> members = userApi.listSubMemberIdsByOrganizationId(organizationDto);
        if (members!=null){
            for (String member : members) {
                memberIds.add(member);
            }
        }

        //根据组织id获取组织架构类型
        UserDto currentUser = UserUtils.getCurrentUser();
        List<SelectorFormat> organization_id = currentUser.getOrganization_id();
        RoleDto roleDto = new RoleDto();
        roleDto.setOrganization_id(organization_id);
        Set<ArchitectureCateEnum> organizationArchitecture = roleApi.getOrganizationArchitecture(roleDto);

        //统计客户要看的
        if (organizationArchitecture.contains(ArchitectureCateEnum.CUSTOMER)){

            Map<String, Object> cushashMap = new HashMap<>();

            //todo：客户今日发布询价商品数
            Map<String, Object> parameter = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSql = new StringBuilder();// 获取总数
            StringBuilder querySql = new StringBuilder();// 查询条件
            StringBuilder listSql = new StringBuilder();// 获取结果


            totalSql.append("select count(ig.id),DATE_FORMAT(ig.createdTime,'%Y-%m-%d') df from (\n");
            querySql.append(InquiryGoodsName).append(" as ig\n");
            querySql.append("left join\n");
            querySql.append(InquiryName).append(" as i\n");
            querySql.append("on i.id = ig.inquiry_id\n");
            querySql.append("where ig.deleted = 0 \n");
            querySql.append("and ig.inquiry_goods_status in (3,4,5)\n");
            querySql.append("and ig.createdTime > STR_TO_DATE(:startFormat,'%Y-%m-%d') \n");
            parameter.put("startFormat",startFormat);
            querySql.append("and ig.createdTime < STR_TO_DATE(:endFormat,'%Y-%m-%d') \n");
            parameter.put("endFormat",endFormat);
            querySql.append("and i.member_id -> '$.id' in (:memberId) \n");
            parameter.put("memberId",memberIds);
            querySql.append("group by df \n");
            querySql.append("order by df \n");

            listSql.append("select count(ig.id),DATE_FORMAT(ig.createdTime,'%Y-%m-%d') df from\n");
            listSql.append(querySql);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSql.toString()));

            List<Map<String, Object>> result = jdbcTemplate.queryForList(listSql.toString(), parameter);
            log.info("-------------------客户今日发布询价商品数：{}-------------------", JSONObject.toJSONString(result));


            //todo：客户今日获得报价次数
            Map<String, Object> parameterTwo = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlTwo = new StringBuilder();// 获取总数
            StringBuilder querySqlTwo = new StringBuilder();// 查询条件
            StringBuilder listSqlTwo = new StringBuilder();// 获取结果


            totalSqlTwo.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from (\n");
            querySqlTwo.append(QuotationGoodsName).append(" as qg\n");
            querySqlTwo.append("left join\n");
            querySqlTwo.append(InquiryGoodsName).append(" as ig\n");
            querySqlTwo.append("on ig.id = qg.inquiry_goods_id \n");
            querySqlTwo.append("left join\n");
            querySqlTwo.append(InquiryName).append(" as i\n");
            querySqlTwo.append("on i.id = ig.inquiry_id\n");
            querySqlTwo.append("where qg.deleted = 0 \n");
            querySqlTwo.append("and qg.quotation_goods_status in (3)\n");
            querySqlTwo.append("and i.member_id -> '$.id' in (:memberId) \n");
            parameterTwo.put("memberId",memberIds);
            querySqlTwo.append("and qg.modifiedTime > STR_TO_DATE(:startFormat,'%Y-%m-%d') \n");
            parameterTwo.put("startFormat",startFormat);
            querySqlTwo.append("and qg.modifiedTime < STR_TO_DATE(:endFormat,'%Y-%m-%d') \n");
            parameterTwo.put("endFormat",endFormat);
            querySqlTwo.append("group by df \n");
            querySqlTwo.append("order by df \n");

            listSqlTwo.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from \n");
            listSqlTwo.append(querySqlTwo);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSqlTwo.toString()));

            List<Map<String, Object>> resultTwo = jdbcTemplate.queryForList(listSqlTwo.toString(), parameterTwo);
            log.info("-------------------客户今日获得报价次数：{}-------------------", JSONObject.toJSONString(resultTwo));



            //todo：询价待审批
            Map<String, Object> parameterStatus = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlStatus = new StringBuilder();// 获取总数
            StringBuilder querySqlStatus = new StringBuilder();// 查询条件
            StringBuilder listSqlStatus = new StringBuilder();// 获取结果

            totalSqlStatus.append("select count(ig.id) as count from (\n");
            querySqlStatus.append(InquiryGoodsName).append(" as ig\n");
            querySqlStatus.append("left join\n");
            querySqlStatus.append(InquiryName).append(" as i\n");
            querySqlStatus.append("on i.id = ig.inquiry_id\n");
            querySqlStatus.append("where ig.deleted = 0 \n");
            querySqlStatus.append("and ig.inquiry_goods_status = 1\n");
            querySqlStatus.append("and i.organization_id -> '$.id' = :organizationId \n");
            parameterStatus.put("organizationId",orgId);

            listSqlStatus.append("select count(ig.id) as count from\n");
            listSqlStatus.append(querySqlStatus);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSqlStatus.toString()));

            List<Map<String, Object>> resultStatus = jdbcTemplate.queryForList(listSqlStatus.toString(), parameterStatus);
            log.info("-------------------询价待审批：{}-------------------", JSONObject.toJSONString(resultStatus));


            //todo：客户昨日发布询价商品数
            Map<String, Object> parameterYd = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlYd = new StringBuilder();// 获取总数
            StringBuilder querySqlYd = new StringBuilder();// 查询条件
            StringBuilder listSqlYd = new StringBuilder();// 获取结果


            totalSqlYd.append("select count( ig.id ),DATE_FORMAT(ig.createdTime,'%Y-%m-%d') df from (\n");
            querySqlYd.append(InquiryGoodsName).append(" as ig\n");
            querySqlYd.append("left join\n");
            querySqlYd.append(InquiryName).append(" as i\n");
            querySqlYd.append("on i.id = ig.inquiry_id\n");
            querySqlYd.append("where ig.deleted = 0 \n");
            querySqlYd.append("and ig.inquiry_goods_status in (3,4,5)\n");
            querySqlYd.append("and ig.createdTime > STR_TO_DATE(:ydStartFormat,'%Y-%m-%d') \n");
            parameterYd.put("ydStartFormat",ydStartFormat);
            querySqlYd.append("and ig.createdTime < STR_TO_DATE(:ydEndFormat,'%Y-%m-%d') \n");
            parameterYd.put("ydEndFormat",ydEndFormat);
            querySqlYd.append("and i.member_id -> '$.id' in (:memberId) \n");
            parameterYd.put("memberId",memberIds);
            querySqlYd.append("group by df \n");
            querySqlYd.append("order by df \n");

            listSqlYd.append("select count( ig.id ),DATE_FORMAT(ig.createdTime,'%Y-%m-%d') df from \n");
            listSqlYd.append(querySqlYd);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSqlYd.toString()));

            List<Map<String, Object>> resultYd = jdbcTemplate.queryForList(listSqlYd.toString(), parameterYd);
            log.info("-------------------客户昨日发布询价商品数：{}-------------------", JSONObject.toJSONString(resultYd));



            //todo：客户昨日获得报价次数
            Map<String, Object> parameterYdTwo = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlYdTwo = new StringBuilder();// 获取总数
            StringBuilder querySqlYdTwo = new StringBuilder();// 查询条件
            StringBuilder listSqlYdTwo = new StringBuilder();// 获取结果


            totalSqlYdTwo.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from (\n");
            querySqlYdTwo.append(QuotationGoodsName).append(" as qg\n");
            querySqlYdTwo.append("left join\n");
            querySqlYdTwo.append(InquiryGoodsName).append(" as ig\n");
            querySqlYdTwo.append("on ig.id = qg.inquiry_goods_id \n");
            querySqlYdTwo.append("left join\n");
            querySqlYdTwo.append(InquiryName).append(" as i\n");
            querySqlYdTwo.append("on i.id = ig.inquiry_id\n");
            querySqlYdTwo.append("where qg.deleted = 0 \n");
            querySqlYdTwo.append("and qg.quotation_goods_status in (3)\n");
            querySqlYdTwo.append("and i.member_id -> '$.id' in (:memberId) \n");
            parameterYdTwo.put("memberId",memberIds);
            querySqlYdTwo.append("and qg.modifiedTime > STR_TO_DATE(:ydStartFormat,'%Y-%m-%d') \n");
            parameterYdTwo.put("ydStartFormat",ydStartFormat);
            querySqlYdTwo.append("and qg.modifiedTime < STR_TO_DATE(:ydEndFormat,'%Y-%m-%d')\n");
            parameterYdTwo.put("ydEndFormat",ydEndFormat);
            querySqlYdTwo.append("group by df \n");
            querySqlYdTwo.append("order by df \n");


            listSqlYdTwo.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from \n");
            listSqlYdTwo.append(querySqlYdTwo);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSqlYdTwo.toString()));

            List<Map<String, Object>> resultYdTwo = jdbcTemplate.queryForList(listSqlYdTwo.toString(), parameterYdTwo);
            log.info("-------------------客户昨日获得报价次数：{}-------------------", JSONObject.toJSONString(resultYdTwo));

            cushashMap.put("tbXj",result);//客户今日发布询价商品数
            cushashMap.put("tbBj",resultTwo);//客户今日获得报价次数
            cushashMap.put("pda",resultStatus);//询价待审批
            cushashMap.put("ydXj",resultYd);//客户昨日发布的询价商品数
            cushashMap.put("ydBj",resultYdTwo);//客户昨日获得报价次数

            hashMaps.put("results",cushashMap);
        }

        //统计供应商要看的
        if (organizationArchitecture.contains(ArchitectureCateEnum.VENDOR)){

            Map<String, Object> venhashMap = new HashMap<>();

            //todo：供应商今日发布报价商品数
            Map<String, Object> parameterVendorTdBj = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlVendorTdBj= new StringBuilder();// 获取总数
            StringBuilder querySqlVendorTdBj = new StringBuilder();// 查询条件
            StringBuilder listSqlVendorTdBj = new StringBuilder();// 获取结果

            totalSqlVendorTdBj.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from (\n");
            querySqlVendorTdBj.append(QuotationGoodsName).append(" as qg\n");
            querySqlVendorTdBj.append("where qg.deleted = 0 \n");
            querySqlVendorTdBj.append("and qg.quotation_goods_status = 3\n");
            querySqlVendorTdBj.append("and qg.modifiedTime > STR_TO_DATE(:startFormat,'%Y-%m-%d') \n");
            parameterVendorTdBj.put("startFormat",startFormat);
            querySqlVendorTdBj.append("and qg.modifiedTime < STR_TO_DATE(:endFormat,'%Y-%m-%d')\n");
            parameterVendorTdBj.put("endFormat",endFormat);
            querySqlVendorTdBj.append("and qg.member_id -> '$.id' in (:memberId) \n");
            parameterVendorTdBj.put("memberId",memberIds);
            querySqlVendorTdBj.append("group by df \n");
            querySqlVendorTdBj.append("order by df \n");


            listSqlVendorTdBj.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from \n");
            listSqlVendorTdBj.append(querySqlVendorTdBj);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSqlVendorTdBj.toString()));

            List<Map<String, Object>> resultTdBj = jdbcTemplate.queryForList(listSqlVendorTdBj.toString(), parameterVendorTdBj);
            log.info("-------------------供应商今日发布报价商品数：{}-------------------", JSONObject.toJSONString(resultTdBj));


            //todo：供应商今日获得定标数
            Map<String, Object> parameterVendorTdDb = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlVendorTdDb= new StringBuilder();// 获取总数
            StringBuilder querySqlVendorTdDb = new StringBuilder();// 查询条件
            StringBuilder listSqlVendorTdDb = new StringBuilder();// 获取结果

            totalSqlVendorTdDb.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from (\n");
            querySqlVendorTdDb.append(QuotationGoodsName).append(" as qg\n");
            querySqlVendorTdDb.append("where qg.deleted = 0 \n");
            querySqlVendorTdDb.append("and qg.picketage = 0 \n");
            querySqlVendorTdDb.append("and qg.modifiedTime > STR_TO_DATE(:startFormat,'%Y-%m-%d')\n");
            parameterVendorTdDb.put("startFormat",startFormat);
            querySqlVendorTdDb.append("and qg.modifiedTime < STR_TO_DATE(:endFormat,'%Y-%m-%d')\n");
            parameterVendorTdDb.put("endFormat",endFormat);
            querySqlVendorTdDb.append("and qg.member_id -> '$.id' in (:memberId) \n");
            parameterVendorTdDb.put("memberId",memberIds);
            querySqlVendorTdDb.append("group by df \n");
            querySqlVendorTdDb.append("order by df \n");

            listSqlVendorTdDb.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from \n");
            listSqlVendorTdDb.append(querySqlVendorTdDb);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSqlVendorTdDb.toString()));

            List<Map<String, Object>> resultTdDb = jdbcTemplate.queryForList(listSqlVendorTdDb.toString(), parameterVendorTdDb);
            log.info("-------------------供应商今日获得定标数：{}-------------------", JSONObject.toJSONString(resultTdDb));


            //todo：供应商今日公开的询价商品
            Map<String, Object> parameterVendorTdGk = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlVendorTdGk= new StringBuilder();// 获取总数
            StringBuilder querySqlVendorTdGk = new StringBuilder();// 查询条件
            StringBuilder listSqlVendorTdGk = new StringBuilder();// 获取结果

            totalSqlVendorTdGk.append("select count( ig.id ),DATE_FORMAT(ig.createdTime, '%Y-%m-%d' ) df from (\n");
            querySqlVendorTdGk.append(InquiryGoodsName).append(" as ig\n");
            querySqlVendorTdGk.append("left join\n");
            querySqlVendorTdGk.append(InquiryName).append(" as i\n");
            querySqlVendorTdGk.append("on i.id = ig.inquiry_id\n");
            querySqlVendorTdGk.append("where ig.deleted = 0 \n");
            querySqlVendorTdGk.append("and ig.inquiry_goods_status in (3,4,5)\n");
            querySqlVendorTdGk.append("and ig.createdTime > STR_TO_DATE(:startFormat,'%Y-%m-%d')\n");
            parameterVendorTdGk.put("startFormat",startFormat);
            querySqlVendorTdGk.append("and ig.createdTime < STR_TO_DATE(:endFormat,'%Y-%m-%d')\n");
            parameterVendorTdGk.put("endFormat",endFormat);
            querySqlVendorTdGk.append("and i.organization_id -> '$.id' = :organizationId \n");
            querySqlVendorTdGk.append("and i.vendor_scope = '2'\n");
            parameterVendorTdGk.put("organizationId",orgId);
            querySqlVendorTdGk.append("group by df \n");
            querySqlVendorTdGk.append("order by df \n");

            listSqlVendorTdGk.append("select count( ig.id ),DATE_FORMAT(ig.createdTime, '%Y-%m-%d' ) df from\n");
            listSqlVendorTdGk.append(querySqlVendorTdGk);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSqlVendorTdGk.toString()));

            List<Map<String, Object>> resultTdGk = jdbcTemplate.queryForList(listSqlVendorTdGk.toString(), parameterVendorTdGk);
            log.info("-------------------供应商今日公开的询价商品：{}-------------------", JSONObject.toJSONString(resultTdGk));


            //todo：供应商今日邀请的询价商品
            Map<String, Object> parameterVendorTdYq = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlVendorTdYq= new StringBuilder();// 获取总数
            StringBuilder querySqlVendorTdYq = new StringBuilder();// 查询条件
            StringBuilder listSqlVendorTdYq = new StringBuilder();// 获取结果

            totalSqlVendorTdYq.append("select count( ig.id ),DATE_FORMAT(ig.createdTime, '%Y-%m-%d' ) df from (\n");
            querySqlVendorTdYq.append(InquiryGoodsName).append(" as ig\n");
            querySqlVendorTdYq.append("left join\n");
            querySqlVendorTdYq.append(InquiryName).append(" as i\n");
            querySqlVendorTdYq.append("on i.id = ig.inquiry_id\n");
            querySqlVendorTdYq.append("where ig.deleted = 0 \n");
            querySqlVendorTdYq.append("and ig.inquiry_goods_status in (3,4,5)\n");
            querySqlVendorTdYq.append("and ig.createdTime > STR_TO_DATE(:startFormat,'%Y-%m-%d')\n");
            parameterVendorTdYq.put("startFormat",startFormat);
            querySqlVendorTdYq.append("and ig.createdTime < STR_TO_DATE(:endFormat,'%Y-%m-%d')\n");
            parameterVendorTdYq.put("endFormat",endFormat);
            querySqlVendorTdYq.append("and i.organization_id -> '$.id' = :organizationId \n");
            querySqlVendorTdYq.append("and i.vendor_scope = '1'\n");
            parameterVendorTdYq.put("organizationId",orgId);
            querySqlVendorTdYq.append("group by df \n");
            querySqlVendorTdYq.append("order by df \n");

            listSqlVendorTdYq.append("select count( ig.id ),DATE_FORMAT(ig.createdTime, '%Y-%m-%d' ) df from\n");
            listSqlVendorTdYq.append(querySqlVendorTdYq);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(listSqlVendorTdYq.toString()));

            List<Map<String, Object>> resultTdYq = jdbcTemplate.queryForList(listSqlVendorTdYq.toString(), parameterVendorTdYq);
            log.info("-------------------供应商今日邀请的询价商品：{}-------------------", JSONObject.toJSONString(resultTdYq));


            //todo：供应商昨日获得定标次数
            Map<String, Object> parameterVendorYdDb = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlVendorYdDb= new StringBuilder();// 获取总数
            StringBuilder querySqlVendorYdDb = new StringBuilder();// 查询条件
            StringBuilder listSqlVendorYdDb = new StringBuilder();// 获取结果

            totalSqlVendorYdDb.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from (\n");
            querySqlVendorYdDb.append(QuotationGoodsName).append(" as qg\n");
            querySqlVendorYdDb.append("left join\n");
            querySqlVendorYdDb.append(InquiryGoodsName).append(" as ig\n");
            querySqlVendorYdDb.append("on ig.id = qg.inquiry_goods_id \n");
            querySqlVendorYdDb.append("left join\n");
            querySqlVendorYdDb.append(InquiryName).append(" as i\n");
            querySqlVendorYdDb.append("on i.id = ig.inquiry_id\n");
            querySqlVendorYdDb.append("where qg.deleted = 0 \n");
            querySqlVendorYdDb.append("and qg.picketage = 0\n");
            querySqlVendorYdDb.append("and qg.modifiedTime > STR_TO_DATE(:ydStartFormat,'%Y-%m-%d') \n");
            parameterVendorYdDb.put("ydStartFormat",ydStartFormat);
            querySqlVendorYdDb.append("and qg.modifiedTime < STR_TO_DATE(:ydEndFormat,'%Y-%m-%d')\n");
            parameterVendorYdDb.put("ydEndFormat",ydEndFormat);
            querySqlVendorYdDb.append("and i.organization_id -> '$.id' in (:organizationId) \n");
            parameterVendorYdDb.put("organizationId",orgId);
            querySqlVendorYdDb.append("group by df \n");
            querySqlVendorYdDb.append("order by df \n");

            listSqlVendorYdDb.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from\n");
            listSqlVendorYdDb.append(querySqlVendorYdDb);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(querySqlVendorYdDb.toString()));

            List<Map<String, Object>> resultYdDb = jdbcTemplate.queryForList(listSqlVendorYdDb.toString(), parameterVendorYdDb);
            log.info("-------------------供应商昨日获得定标次数：{}-------------------", JSONObject.toJSONString(resultYdDb));

            venhashMap.put("tdBj",resultTdBj);//供应商今日发布报价商品数
            venhashMap.put("tdDb",resultTdDb);//供应商今日获得定标数
            venhashMap.put("tdGkXj",resultTdGk);//供应商今日公开的询价商品数
            venhashMap.put("tdYq",resultTdYq);//供应商今日邀请的询价商品数
            venhashMap.put("ydDb",resultYdDb);//供应商昨日获得定标次数

            hashMaps.put("results",venhashMap);
        }


        //统计平台要看的
        if (organizationArchitecture.contains(ArchitectureCateEnum.PM)){

            Map<String, Object> pmhashMap = new HashMap<>();

            //todo：云平台今日询报价数
            Map<String, Object> parameterPmXb = Maps.newHashMap();
            // 拼接sql
            StringBuilder querySqlPmXb = new StringBuilder();// 查询条件
            StringBuilder listSqlPmXb = new StringBuilder();// 获取结果

            querySqlPmXb.append("select count( qg.id ) qgc from \n");
            querySqlPmXb.append(QuotationGoodsName).append(" as qg\n");
            querySqlPmXb.append("where qg.deleted = 0 \n");
            querySqlPmXb.append("and qg.quotation_goods_status = 3 \n");
            querySqlPmXb.append("and qg.modifiedTime > STR_TO_DATE(:startFormat,'%Y-%m-%d') \n");
            parameterPmXb.put("startFormat",startFormat);
            querySqlPmXb.append("and qg.modifiedTime < STR_TO_DATE(:endFormat,'%Y-%m-%d')\n");
            parameterPmXb.put("endFormat",endFormat);
            querySqlPmXb.append(") igc from\n");
            querySqlPmXb.append(InquiryGoodsName).append(" as ig\n");
            querySqlPmXb.append("where ig.deleted = 0 \n");
            querySqlPmXb.append("and ig.inquiry_goods_status = 3  \n");
            querySqlPmXb.append("and ig.createdTime > STR_TO_DATE(:startFormat,'%Y-%m-%d')\n");
            parameterPmXb.put("startFormat",startFormat);
            querySqlPmXb.append("and ig.createdTime < STR_TO_DATE(:endFormat,'%Y-%m-%d')\n");
            parameterPmXb.put("endFormat",endFormat);

            listSqlPmXb.append("select count( ig.id )+( \n");
            listSqlPmXb.append(querySqlPmXb);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(querySqlPmXb.toString()));

            List<Map<String, Object>> resultPmXb = jdbcTemplate.queryForList(listSqlPmXb.toString(), parameterPmXb);
            log.info("-------------------云平台今日询报价数：{}-------------------", JSONObject.toJSONString(resultPmXb));

            //todo：平台今日询价商品数
            Map<String, Object> parameterPmTdXj = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlPmTdXj= new StringBuilder();// 获取总数
            StringBuilder querySqlPmTdXj = new StringBuilder();// 查询条件
            StringBuilder listSqlPmTdXj = new StringBuilder();// 获取结果

            totalSqlPmTdXj.append("select count( ig.id ),DATE_FORMAT(ig.createdTime, '%Y-%m-%d' ) df from (\n");
            querySqlPmTdXj.append(InquiryGoodsName).append(" as ig\n");
            querySqlPmTdXj.append("where ig.deleted = 0 \n");
            querySqlPmTdXj.append("and ig.inquiry_goods_status in (3,4,5)\n");
            querySqlPmTdXj.append("and ig.createdTime > STR_TO_DATE(:startFormat,'%Y-%m-%d')\n");
            parameterPmTdXj.put("startFormat",startFormat);
            querySqlPmTdXj.append("and ig.createdTime < STR_TO_DATE(:endFormat,'%Y-%m-%d')\n");
            parameterPmTdXj.put("endFormat",endFormat);
            querySqlPmTdXj.append("group by df \n");
            querySqlPmTdXj.append("order by df \n");

            listSqlPmTdXj.append("select count( ig.id ),DATE_FORMAT(ig.createdTime, '%Y-%m-%d' ) df from \n");
            listSqlPmTdXj.append(querySqlPmTdXj);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(querySqlPmTdXj.toString()));

            List<Map<String, Object>> resultPmTdXj = jdbcTemplate.queryForList(listSqlPmTdXj.toString(), parameterPmTdXj);
            log.info("-------------------云平台今日询价商品数：{}-------------------", JSONObject.toJSONString(resultPmTdXj));


            //todo：平台今日定标次数
            Map<String, Object> parameterPmTdDb = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlPmTdDb= new StringBuilder();// 获取总数
            StringBuilder querySqlPmTdDb = new StringBuilder();// 查询条件
            StringBuilder listSqlPmTdDb = new StringBuilder();// 获取结果

            totalSqlPmTdDb.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from (\n");
            querySqlPmTdDb.append(QuotationGoodsName).append(" as qg\n");
            querySqlPmTdDb.append("where qg.deleted = 0 \n");
            querySqlPmTdDb.append("and qg.picketage = 0\n");
            querySqlPmTdDb.append("and qg.modifiedTime > STR_TO_DATE(:startFormat,'%Y-%m-%d') \n");
            parameterPmTdDb.put("startFormat",startFormat);
            querySqlPmTdDb.append("and qg.modifiedTime < STR_TO_DATE(:endFormat,'%Y-%m-%d')\n");
            parameterPmTdDb.put("endFormat",endFormat);
            querySqlPmTdDb.append("group by df \n");
            querySqlPmTdDb.append("order by df \n");

            listSqlPmTdDb.append("select count( qg.id ),DATE_FORMAT(qg.modifiedTime,'%Y-%m-%d') df from \n");
            listSqlPmTdDb.append(querySqlPmTdDb);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(querySqlPmTdDb.toString()));

            List<Map<String, Object>> resultPmTdDb = jdbcTemplate.queryForList(listSqlPmTdDb.toString(), parameterPmTdDb);
            log.info("-------------------平台今日定标次数：{}-------------------", JSONObject.toJSONString(resultPmTdDb));

            //todo：平台昨日询价商品数
            Map<String, Object> parameterPmYdXj = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlPmYdXj= new StringBuilder();// 获取总数
            StringBuilder querySqlPmYdXj = new StringBuilder();// 查询条件
            StringBuilder listSqlPmYdXj = new StringBuilder();// 获取结果

            totalSqlPmYdXj.append("select count( ig.id ),DATE_FORMAT(ig.createdTime, '%Y-%m-%d' ) df from (\n");
            querySqlPmYdXj.append(InquiryGoodsName).append(" as ig\n");
            querySqlPmYdXj.append("where ig.deleted = 0 \n");
            querySqlPmYdXj.append("and ig.inquiry_goods_status in (3,4,5)\n");
            querySqlPmYdXj.append("and ig.createdTime > STR_TO_DATE(:ydStartFormat,'%Y-%m-%d')\n");
            parameterPmYdXj.put("ydStartFormat",ydStartFormat);
            querySqlPmYdXj.append("and ig.createdTime < STR_TO_DATE(:ydEndFormat,'%Y-%m-%d')\n");
            parameterPmYdXj.put("ydEndFormat",endFormat);
            querySqlPmYdXj.append("group by df \n");
            querySqlPmYdXj.append("order by df \n");

            listSqlPmYdXj.append("select count( ig.id ),DATE_FORMAT(ig.createdTime, '%Y-%m-%d' ) df from \n");
            listSqlPmYdXj.append(querySqlPmYdXj);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(parameterPmYdXj.toString()));

            List<Map<String, Object>> resultPmYdXj = jdbcTemplate.queryForList(listSqlPmYdXj.toString(), parameterPmYdXj);
            log.info("-------------------云平台昨日询价商品数：{}-------------------", JSONObject.toJSONString(resultPmYdXj));



            //todo：平台昨日报价次数
            Map<String, Object> parameterPmYdBj = Maps.newHashMap();
            // 拼接sql
            StringBuilder totalSqlPmYdBj= new StringBuilder();// 获取总数
            StringBuilder querySqlPmYdBj = new StringBuilder();// 查询条件
            StringBuilder listSqlPmYdBj = new StringBuilder();// 获取结果

            totalSqlPmYdBj.append("select count( qg.id ),DATE_FORMAT( qg.modifiedTime, '%Y-%m-%d' ) df from (\n");
            querySqlPmYdBj.append(QuotationGoodsName).append(" as qg\n");
            querySqlPmYdBj.append("where qg.deleted = 0 \n");
            querySqlPmYdBj.append("and qg.quotation_goods_status NOT IN (0,1,2)\n");
            querySqlPmYdBj.append("and qg.modifiedTime > STR_TO_DATE(:ydStartFormat,'%Y-%m-%d')\n");
            parameterPmYdBj.put("ydStartFormat",ydStartFormat);
            querySqlPmYdBj.append("and qg.modifiedTime < STR_TO_DATE(:ydEndFormat,'%Y-%m-%d')\n");
            parameterPmYdBj.put("ydEndFormat",endFormat);
            querySqlPmYdBj.append("group by df \n");
            querySqlPmYdBj.append("order by df \n");

            listSqlPmYdBj.append("select count( qg.id ),DATE_FORMAT( qg.modifiedTime, '%Y-%m-%d' ) df from \n");
            listSqlPmYdBj.append(querySqlPmYdBj);
            log.info("-------------------sql语句：{}-------------------", JSONObject.toJSONString(parameterPmYdBj.toString()));

            List<Map<String, Object>> resultPmYdBj = jdbcTemplate.queryForList(listSqlPmYdBj.toString(), parameterPmYdBj);
            log.info("-------------------云平台昨日报价次数：{}-------------------", JSONObject.toJSONString(resultPmYdBj));

            pmhashMap.put("tdXbj",resultPmXb);//云平台今日询报价数
            pmhashMap.put("tdXj",resultPmTdXj);//云平台今日询价商品数
            pmhashMap.put("tdDb",resultPmTdDb);//云平台今日定标次数
            pmhashMap.put("ydXj",resultPmYdXj);//云平台昨日询价商品数
            pmhashMap.put("ydBj",resultPmYdBj);//云平台昨日报价次数

            hashMaps.put("results",pmhashMap);
        }
        return hashMaps;
    }
}

